package com.xtm.exercise.menu;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xtm.common.model.SysMenu;
import com.xtm.common.service.impl.SuperServiceImpl;
import com.xtm.exercise.menu.base.IMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜单模块 - 服务层
 */
@Slf4j
@Service
public class MenuService extends SuperServiceImpl<MenuMapper, SysMenu> implements IMenuService {

    /**
     * 查询所有菜单
     */
	@Override
	public List<SysMenu> findAll () {
		return baseMapper.selectList(new QueryWrapper<SysMenu>().orderByAsc("sort"));
	}

	/**
	 * 新增菜单
	 */
	@Override
	public int addMenu (SysMenu menu) {
		if (menu.getId() == null) {
			menu.setId(80L);
			menu.setCreateUser("1");
		}
		return baseMapper.insert(menu);
	}

	/**
	 * 删除菜单
	 */
	@Override
	public int delMenu (Long id) {
		return baseMapper.deleteById(id);
	}

}